package com.sl.au.repository;

import java.util.List;

import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.transaction.annotation.Transactional;

import com.sl.au.entity.ExdeBeforeContractCounterSign;

public interface ExdeBeforeContractHQDetailRepository extends JpaRepository<ExdeBeforeContractCounterSign, String>{
	
	@Query("select e from ExdeBeforeContractCounterSign e where e.exdeBeforeContract.id=?1 and e.user.id=?2 and e.cAuditState=0 ")
	List<ExdeBeforeContractCounterSign> getExdeBeforeContractCounterSignByUserIdList(String beforeId,String UserId);
	/***
	 * 通过签订前要点审批ID查询会签人List
	 * @param beforeId
	 * @param pageable
	 * @return
	 */
	@Query("select e from ExdeBeforeContractCounterSign e where e.exdeBeforeContract.id=?1")
	Page<ExdeBeforeContractCounterSign> getBeforeContractsCounterSignList(String beforeId,Pageable pageable);
	
	/***
	 * 通过签订前要点审批ID查询会签人Count
	 * @param key
	 * @return
	 */
	@Query("select count(e) from ExdeBeforeContractCounterSign e where e.exdeBeforeContract.id=?1")
	long getBeforeContractsCounterSignCount(String beforeId);
	
	/***
	 * 通过签订前要点审批ID查询为审批子表Count
	 * @param key
	 * @return
	 */
	@Query("select count(e) from ExdeBeforeContractCounterSign e where e.exdeBeforeContract.id=?1 and e.cAuditState=0 ")
	long getBeforeContractsCounterSignFinishCount(String beforeId);
	
	
	/***
	 * 通过签订前要点审批ID查询会签人List
	 * @param beforeId
	 * @param pageable
	 * @return
	 */
	@Query("select e from ExdeBeforeContractCounterSign e where e.user.id=?1 and e.cAuditState=0 ")
	Page<ExdeBeforeContractCounterSign> getBeforeContractsCounterSignByUserIdList(String userId,Pageable pageable);
	
	@Transactional
	@Modifying
	@Query("delete from ExdeBeforeContractCounterSign e where e.id=?")
	void deleteById(String id);
	
}
